#include "Logger.h"


namespace devii
{

Logger & log()
{
	static Logger log("log.txt");
	return log;
}

Logger::Logger()
{
	std::stringstream ss;
	ss << "Log.txt";
	std::cout << "Logger: " << ss.str() << std::endl;
	out.open(ss.str(), std::ios::out);
	if(!out.is_open())
		std::cout << "File aint open" << std::endl;
	else
		write("Logger", "Logger created");
}

Logger::~Logger()
{
	if(out.is_open())
		out.close();
}

Logger::Logger(const std::string & filename)
{
	std::stringstream ss;
	ss << filename;
	std::cout << "Logger: " << ss.str() << std::endl;
	out.open(ss.str(), std::ios::out);
	if(!out.is_open())
		std::cout << "File aint open" << std::endl;
	else
		write("Logger", "A Logger is created");
}

void Logger::write(const std::string & text)
{
	char date[10];
	char time[10];
	_strdate_s(date);
	_strtime_s(time);

	std::stringstream ss;
	ss << "[" << date << " " << time << "][" << "NULL" << "]" << " - " << text << "\n";
	std::string temp = ss.str();
	out.write(temp.c_str(), temp.length());

	out.flush();
}

void Logger::write(const std::string & parent, const std::string & text)
{
	char date[10];
	char time[10];
	_strdate_s(date);
	_strtime_s(time);

	std::stringstream ss;
	ss << "[" << date << " " << time << "][" << parent << "]" << " - " << text << "\n";
	std::string temp = ss.str();
	out.write(temp.c_str(), temp.length());

	out.flush();
}

}